﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net.Http;
#if WINRT
using System.Net;
#endif
namespace MetroDropBox.Shared
{
    public class OAuthToken
    {
        protected OAuthToken() { }

        public OAuthToken(string result)
        {
            originalString = result;

            var items = result.Split('&');
            if (items.Count() > 0)
            {
                foreach (var item in items)
                {
                    var kvp = item.Split('=');
                    if (kvp.Count() > 0)
                        switch (kvp[0].ToLowerInvariant())
                        {
                            case "oauth_token":
                                Token = WebUtility.UrlDecode( kvp[1]);
                                break;
                            case "access_token":
                                Token = WebUtility.UrlDecode( kvp[1]);
                                break;
                            case "oauth_token_secret":
                                Secret = WebUtility.UrlDecode( kvp[1]);
                                break;
                            case "token_type":
                                TokenType = WebUtility.UrlDecode(kvp[1]);
                                break;
                            default:
                                break;
                        }
                }
            }
        }

        protected string originalString;
        public string Token { get; protected set; }
        public string Secret { get; protected set; }

        public string TokenType { get; set; }

        public override string ToString()
        {
            return originalString;
        }
    }
}
